﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer.Properties;
using IMModel.Domain;

namespace DataAccessLayer.Admin.Copy.UniversityStruct
{
    public class RespondentCopy : ICopy
    {
        public int Copy(int IDCopiedObject, int? IDParentObject, int fromIDTerm, int toIDTerm)
        {
            using (IMModel.Domain.IMDataDataContext db = new IMModel.Domain.IMDataDataContext(Settings.Default.IndexMarkConnectionString))
            {
                if (IDParentObject == null)
                {
                    throw new ArgumentException("IDParentObject не может быть == NULL");
                }

                Respondent old = db.Respondents.Single(s => s.IDRespondent == IDCopiedObject);

                Respondent _new = new Respondent
                {
                    IDPerson = old.IDPerson,
                    IDDepartmentTerm = (int)IDParentObject,
                    IDJob = old.IDJob,
                    FlagOsnJob = old.FlagOsnJob,
                    IgnoreVolumes = old.IgnoreVolumes
                };
                db.Respondents.InsertOnSubmit(_new);
                db.SubmitChanges();

                return _new.IDRespondent;
            }
        }
    }
}
